<template>
  <div>
    <!-- 索赔结算单选择页面 -->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="110" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button type="primary" @click="saveDialog">添 加</multiuse-button>
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
  </div>
</template>
<script>
  import { getListByPage, getPartType } from '@/api/claim/dealer/ClaimStatementMaintain';
  import {  getAppId } from '@/assets/js/auth';
  export default {
    components: {
    },
    data() {
      return {
        dataList: [],
        visibleDrawer: false,
        collapse: false,
        infoId: null,
        editRow: {},
        rowData: {},
        topFilterInit: this.topFilterInitFun(),
        flterValue: {}, //参数
        fetchapi: getListByPage,
        columns: this.creatHeader(),
        fetchParams: {settleStatus:55461002 ,statusForFlag:3}, //ipa 接口
        selectedRows: [], //选中经销商
        visibleAdd: false
      };
    },
    created() {
      this.chuqi();
    },
    methods: {
      //保存
      saveDialog() {
        console.log(this.selectedRows)
        this.$emit('save', this.selectedRows);
      },
      //取消操作
      closeDialog() {
        this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
      },
      //翻译
      async chuqi() {
        const res = await getPartType({ type: 5543 });
        if(getAppId()=='arcfox') {
          delete res.data[0]
        }
        if (res.resultCode == 200) {
          this.topFilterInit.find(x => x.fieldName == 'carType').initialValue = '';
          this.topFilterInit.find(x => x.fieldName == 'carType').itemList = res.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
        };
      },
      //搜索数据
      topFilterInitFun() {
        return [
          { type: 'INPUT', label: '结算单号', fieldName: 'settleNo', placeholder: '请输入结算单号...', initialValue: '' },
          { type: 'SELECT', label: '索赔车辆属性', fieldName: 'carType', placeholder: '请选择索赔车辆属性...', initialValue: '', itemList: [] },
          {
            type: 'RANGE_DATE',
            label: '提交时间',
            fieldName: 'beginSettleDate|endSettleDate',
            placeholder: '请输入',
            initialValue: ''
          }
        ];
      },
      //搜索获取数据
      changeHandle(val) {
        this.fetchParams = Object.assign({settleStatus:55461002,statusForFlag:3}, this.fetchParams, val);
        console.log(val);
      },
      //table表头和数据源
      creatHeader() {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 80,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          { title: '状态', dataIndex: 'settleStatusStr', sorter: true },
          { title: '经销商代码', dataIndex: 'ownerCode', sorter: true },
          { title: '经销商名称', dataIndex: 'dealerName', sorter: true },
          { title: '结算单号', dataIndex: 'settleNo', sorter: true },
          { title: '索赔车辆属性', dataIndex: 'carTypeStr', sorter: true },
          { title: '索赔单数', dataIndex: 'claimCount', sorter: true },
          { title: '结算金额', dataIndex: 'settleAmount', sorter: true },
          { title: '考核金额', dataIndex: 'assessAmount', sorter: true },
          { title: '提交时间', dataIndex: 'applyDate', sorter: true },
          { title: '主键', dataIndex: 'settleId', hidden: true }
        ];
      },
      //选中
      selectChange(rows) {
        this.selectedRows = rows;
        console.log(this.selectedRows);
      },
      add() {
        this.visibleAdd = true;
      },
      closeAdd() {
        this.visibleAdd = false;
        this.fetchParams = { ...this.fetchParams };
      },

      saveAdd() {
        this.visibleAdd = false;
        this.fetchParams = { ...this.fetchParams };
      },

    }
    // mounted() {
    //   this.BaseTable = this.$refs.listModal.$refs.pageTable;
    // }
  };
</script>

<style lang="less" scoped></style>
